﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace Collector.LogServer
{
    class FtpSever
    {
        [DllImport("ftpuploadlib.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        public static extern bool UploadFileToFTPA(string ip, string user, string pwd, string remoteFile, string localFile);
        
        public static bool uploaderFileToFtp(string remoteFolderPath, string localFile)
        {
            if(!FileConfig.CommonParam.UploadLogEnable)
            {
                return true;
            }

            remoteFolderPath = remoteFolderPath.Replace("\\", "/");

            string ip = FileConfig.CommonParam.UploadIpaddress;
            string user = FileConfig.CommonParam.UploadUser;
            string pwd = FileConfig.CommonParam.UploadPwd;
            string remoteDir = FileConfig.CommonParam.uploaderRemoteFolder + remoteFolderPath;

            if(!UploadFileToFTPA(ip, user, pwd, remoteDir, localFile))
            {
                return false;
            }

            return true;
        }
    }
}
